{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 缺失数据处理\n",
    "DataFrame的数据处理与规整。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>8.536671</td>\n",
       "      <td>1.230723</td>\n",
       "      <td>9.081591</td>\n",
       "      <td>5.851405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.871290</td>\n",
       "      <td>5.855791</td>\n",
       "      <td>7.359310</td>\n",
       "      <td>6.300424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.562549</td>\n",
       "      <td>6.235347</td>\n",
       "      <td>2.733156</td>\n",
       "      <td>0.478166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.544264</td>\n",
       "      <td>0.003022</td>\n",
       "      <td>1.976443</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>7.370109</td>\n",
       "      <td>7.391061</td>\n",
       "      <td>2.631217</td>\n",
       "      <td>6.587336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>3.648107</td>\n",
       "      <td>9.791748</td>\n",
       "      <td>1.520625</td>\n",
       "      <td>6.372248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>NaN</td>\n",
       "      <td>4.643289</td>\n",
       "      <td>2.242816</td>\n",
       "      <td>1.893602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.837096</td>\n",
       "      <td>9.037081</td>\n",
       "      <td>5.947729</td>\n",
       "      <td>0.781683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>4.602054</td>\n",
       "      <td>7.434672</td>\n",
       "      <td>1.145279</td>\n",
       "      <td>4.799661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>1.529048</td>\n",
       "      <td>1.468754</td>\n",
       "      <td>4.790592</td>\n",
       "      <td>5.044345</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  8.536671  1.230723  9.081591  5.851405\n",
       "2019-06-02  9.871290  5.855791  7.359310  6.300424\n",
       "2019-06-03  6.562549  6.235347  2.733156  0.478166\n",
       "2019-06-04  4.544264  0.003022  1.976443       NaN\n",
       "2019-06-05  7.370109  7.391061  2.631217  6.587336\n",
       "2019-06-06  3.648107  9.791748  1.520625  6.372248\n",
       "2019-06-07       NaN  4.643289  2.242816  1.893602\n",
       "2019-06-08  6.837096  9.037081  5.947729  0.781683\n",
       "2019-06-09  4.602054  7.434672  1.145279  4.799661\n",
       "2019-06-10  1.529048  1.468754  4.790592  5.044345"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "zreo_one_distribute = np.random.rand(10,4)*10 # 10行4列\n",
    "list = ['open','high','low','close']\n",
    "df1 = pd.DataFrame(zreo_one_distribute, index=dates, columns=list)\n",
    "\n",
    "# 将特定数据置为NaN\n",
    "df1.loc['2019-06-04','close']=np.nan\n",
    "df1.loc['2019-06-07','open']=np.nan\n",
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 去掉包含缺失值的行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>8.536671</td>\n",
       "      <td>1.230723</td>\n",
       "      <td>9.081591</td>\n",
       "      <td>5.851405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.871290</td>\n",
       "      <td>5.855791</td>\n",
       "      <td>7.359310</td>\n",
       "      <td>6.300424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.562549</td>\n",
       "      <td>6.235347</td>\n",
       "      <td>2.733156</td>\n",
       "      <td>0.478166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>7.370109</td>\n",
       "      <td>7.391061</td>\n",
       "      <td>2.631217</td>\n",
       "      <td>6.587336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>3.648107</td>\n",
       "      <td>9.791748</td>\n",
       "      <td>1.520625</td>\n",
       "      <td>6.372248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.837096</td>\n",
       "      <td>9.037081</td>\n",
       "      <td>5.947729</td>\n",
       "      <td>0.781683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>4.602054</td>\n",
       "      <td>7.434672</td>\n",
       "      <td>1.145279</td>\n",
       "      <td>4.799661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>1.529048</td>\n",
       "      <td>1.468754</td>\n",
       "      <td>4.790592</td>\n",
       "      <td>5.044345</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  8.536671  1.230723  9.081591  5.851405\n",
       "2019-06-02  9.871290  5.855791  7.359310  6.300424\n",
       "2019-06-03  6.562549  6.235347  2.733156  0.478166\n",
       "2019-06-05  7.370109  7.391061  2.631217  6.587336\n",
       "2019-06-06  3.648107  9.791748  1.520625  6.372248\n",
       "2019-06-08  6.837096  9.037081  5.947729  0.781683\n",
       "2019-06-09  4.602054  7.434672  1.145279  4.799661\n",
       "2019-06-10  1.529048  1.468754  4.790592  5.044345"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.dropna()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 对缺失值进行填充"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>8.536671</td>\n",
       "      <td>1.230723</td>\n",
       "      <td>9.081591</td>\n",
       "      <td>5.851405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.871290</td>\n",
       "      <td>5.855791</td>\n",
       "      <td>7.359310</td>\n",
       "      <td>6.300424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.562549</td>\n",
       "      <td>6.235347</td>\n",
       "      <td>2.733156</td>\n",
       "      <td>0.478166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.544264</td>\n",
       "      <td>0.003022</td>\n",
       "      <td>1.976443</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>7.370109</td>\n",
       "      <td>7.391061</td>\n",
       "      <td>2.631217</td>\n",
       "      <td>6.587336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>3.648107</td>\n",
       "      <td>9.791748</td>\n",
       "      <td>1.520625</td>\n",
       "      <td>6.372248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>4.643289</td>\n",
       "      <td>2.242816</td>\n",
       "      <td>1.893602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.837096</td>\n",
       "      <td>9.037081</td>\n",
       "      <td>5.947729</td>\n",
       "      <td>0.781683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>4.602054</td>\n",
       "      <td>7.434672</td>\n",
       "      <td>1.145279</td>\n",
       "      <td>4.799661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>1.529048</td>\n",
       "      <td>1.468754</td>\n",
       "      <td>4.790592</td>\n",
       "      <td>5.044345</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  8.536671  1.230723  9.081591  5.851405\n",
       "2019-06-02  9.871290  5.855791  7.359310  6.300424\n",
       "2019-06-03  6.562549  6.235347  2.733156  0.478166\n",
       "2019-06-04  4.544264  0.003022  1.976443  0.000000\n",
       "2019-06-05  7.370109  7.391061  2.631217  6.587336\n",
       "2019-06-06  3.648107  9.791748  1.520625  6.372248\n",
       "2019-06-07  0.000000  4.643289  2.242816  1.893602\n",
       "2019-06-08  6.837096  9.037081  5.947729  0.781683\n",
       "2019-06-09  4.602054  7.434672  1.145279  4.799661\n",
       "2019-06-10  1.529048  1.468754  4.790592  5.044345"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将缺失值填充为指定值\n",
    "df1.fillna(value=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 判断数据是否为NaN，并进行bool填充"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high    low  close\n",
       "2019-06-01  False  False  False  False\n",
       "2019-06-02  False  False  False  False\n",
       "2019-06-03  False  False  False  False\n",
       "2019-06-04  False  False  False   True\n",
       "2019-06-05  False  False  False  False\n",
       "2019-06-06  False  False  False  False\n",
       "2019-06-07   True  False  False  False\n",
       "2019-06-08  False  False  False  False\n",
       "2019-06-09  False  False  False  False\n",
       "2019-06-10  False  False  False  False"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 是NaN则填充True，非NaN则填充False\n",
    "pd.isnull(df1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 函数的应用和映射"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>8.536671</td>\n",
       "      <td>1.230723</td>\n",
       "      <td>9.081591</td>\n",
       "      <td>5.851405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>9.871290</td>\n",
       "      <td>5.855791</td>\n",
       "      <td>7.359310</td>\n",
       "      <td>6.300424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.562549</td>\n",
       "      <td>6.235347</td>\n",
       "      <td>2.733156</td>\n",
       "      <td>0.478166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.544264</td>\n",
       "      <td>0.003022</td>\n",
       "      <td>1.976443</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>7.370109</td>\n",
       "      <td>7.391061</td>\n",
       "      <td>2.631217</td>\n",
       "      <td>6.587336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>3.648107</td>\n",
       "      <td>9.791748</td>\n",
       "      <td>1.520625</td>\n",
       "      <td>6.372248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>NaN</td>\n",
       "      <td>4.643289</td>\n",
       "      <td>2.242816</td>\n",
       "      <td>1.893602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.837096</td>\n",
       "      <td>9.037081</td>\n",
       "      <td>5.947729</td>\n",
       "      <td>0.781683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>4.602054</td>\n",
       "      <td>7.434672</td>\n",
       "      <td>1.145279</td>\n",
       "      <td>4.799661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>1.529048</td>\n",
       "      <td>1.468754</td>\n",
       "      <td>4.790592</td>\n",
       "      <td>5.044345</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  8.536671  1.230723  9.081591  5.851405\n",
       "2019-06-02  9.871290  5.855791  7.359310  6.300424\n",
       "2019-06-03  6.562549  6.235347  2.733156  0.478166\n",
       "2019-06-04  4.544264  0.003022  1.976443       NaN\n",
       "2019-06-05  7.370109  7.391061  2.631217  6.587336\n",
       "2019-06-06  3.648107  9.791748  1.520625  6.372248\n",
       "2019-06-07       NaN  4.643289  2.242816  1.893602\n",
       "2019-06-08  6.837096  9.037081  5.947729  0.781683\n",
       "2019-06-09  4.602054  7.434672  1.145279  4.799661\n",
       "2019-06-10  1.529048  1.468754  4.790592  5.044345"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open     5.944577\n",
       "high     5.309149\n",
       "low      3.942876\n",
       "close    4.234319\n",
       "dtype: float64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算每列的平均值\n",
    "df1.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    6.175098\n",
       "2019-06-02    7.346704\n",
       "2019-06-03    4.002305\n",
       "2019-06-04    2.174576\n",
       "2019-06-05    5.994931\n",
       "2019-06-06    5.333182\n",
       "2019-06-07    2.926569\n",
       "2019-06-08    5.650897\n",
       "2019-06-09    4.495417\n",
       "2019-06-10    3.208185\n",
       "Freq: D, dtype: float64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算每行的平均值\n",
    "df1.mean(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    6.175098\n",
       "2019-06-02    7.346704\n",
       "2019-06-03    4.002305\n",
       "2019-06-04         NaN\n",
       "2019-06-05    5.994931\n",
       "2019-06-06    5.333182\n",
       "2019-06-07         NaN\n",
       "2019-06-08    5.650897\n",
       "2019-06-09    4.495417\n",
       "2019-06-10    3.208185\n",
       "Freq: D, dtype: float64"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# skippa参数默认是True，表示排除缺失值\n",
    "df1.mean(axis=\"columns\", skipna=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open          NaN\n",
       "high     5.309149\n",
       "low      3.942876\n",
       "close         NaN\n",
       "dtype: float64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# skippa参数默认是True，表示排除缺失值\n",
    "df1.mean(axis=\"index\", skipna=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "常用的方法如上所介绍，还有其他许多，下面罗列了一些，可供参考:\n",
    "- count非na值的数量；\n",
    "- describe 针对Series或单个DataFrame列做计算汇总统计；\n",
    "- max、min 计算最大值或最小值；\n",
    "- argmin、argmax 计算能够获取到的最大值和最小值的索引位置（整数）；\n",
    "- idxmin、inxmax 计算能够获取到的最大值和最小值的索引位值；\n",
    "- sum 值的总和；\n",
    "- mean 值的平均数；\n",
    "- median 值的算术中位数（50%分位数）；\n",
    "- mad 根据平均值计算平均绝对离差；\n",
    "- var 样本值的方差；\n",
    "- std 样本值的标准差； \n",
    "- skew 样本值的偏度（三阶矩）；\n",
    "- kurt 样本值的峰度（四阶矩）；\n",
    "- cumsum 样本值的累计和；\n",
    "- cummin、cummax 样本值的累计最大值和累计最小值；\n",
    "- cumprod 样本值的累计积；\n",
    "- diff 计算一阶差分（对时间序列很有用）；\n",
    "- pct_change 计算百分数变化。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据规整\n",
    "Pandas 提供了大量的方法能够轻松的对Series、DataFrame和Panel对象进行各种符合逻辑关系的合并操作：\n",
    "- concat 可以沿一条轴将多个对象堆叠到一起；\n",
    "- append 将一行连接到一个DataFrame上；\n",
    "- duplicate 移除重复数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>4.575004</td>\n",
       "      <td>9.456158</td>\n",
       "      <td>7.072233</td>\n",
       "      <td>7.339954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.448908</td>\n",
       "      <td>0.949864</td>\n",
       "      <td>5.550604</td>\n",
       "      <td>6.062410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>8.779756</td>\n",
       "      <td>4.377672</td>\n",
       "      <td>5.888814</td>\n",
       "      <td>1.621226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.814200</td>\n",
       "      <td>6.065218</td>\n",
       "      <td>3.297106</td>\n",
       "      <td>3.688930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.817728</td>\n",
       "      <td>6.706026</td>\n",
       "      <td>5.447670</td>\n",
       "      <td>5.185773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.124675</td>\n",
       "      <td>0.461762</td>\n",
       "      <td>3.937787</td>\n",
       "      <td>3.695477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.157564</td>\n",
       "      <td>0.449706</td>\n",
       "      <td>3.000842</td>\n",
       "      <td>4.793000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>3.951076</td>\n",
       "      <td>7.059597</td>\n",
       "      <td>8.345769</td>\n",
       "      <td>0.938861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>8.107833</td>\n",
       "      <td>6.684679</td>\n",
       "      <td>6.655880</td>\n",
       "      <td>7.739734</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  5.192434  5.216640  4.693987  4.987835\n",
       "2019-06-02  4.575004  9.456158  7.072233  7.339954\n",
       "2019-06-03  6.448908  0.949864  5.550604  6.062410\n",
       "2019-06-04  8.779756  4.377672  5.888814  1.621226\n",
       "2019-06-05  8.814200  6.065218  3.297106  3.688930\n",
       "2019-06-06  7.817728  6.706026  5.447670  5.185773\n",
       "2019-06-07  9.124675  0.461762  3.937787  3.695477\n",
       "2019-06-08  6.157564  0.449706  3.000842  4.793000\n",
       "2019-06-09  3.951076  7.059597  8.345769  0.938861\n",
       "2019-06-10  8.107833  6.684679  6.655880  7.739734"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates3_1 = pd.date_range('20190601', periods=10)\n",
    "zreo_one_distribute = np.random.rand(10,4)*10 # 10行4列\n",
    "list = ['open','high','low','close']\n",
    "df3_1 = pd.DataFrame(zreo_one_distribute, index=dates3_1, columns=list)\n",
    "df3_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-07-01</th>\n",
       "      <td>0.844460</td>\n",
       "      <td>6.739471</td>\n",
       "      <td>3.788768</td>\n",
       "      <td>8.164879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-02</th>\n",
       "      <td>2.249147</td>\n",
       "      <td>1.227615</td>\n",
       "      <td>7.817358</td>\n",
       "      <td>0.421079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-03</th>\n",
       "      <td>3.858455</td>\n",
       "      <td>6.100323</td>\n",
       "      <td>1.066838</td>\n",
       "      <td>6.624229</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-04</th>\n",
       "      <td>9.567775</td>\n",
       "      <td>7.707239</td>\n",
       "      <td>8.438617</td>\n",
       "      <td>6.708416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-05</th>\n",
       "      <td>6.514836</td>\n",
       "      <td>8.544937</td>\n",
       "      <td>9.145777</td>\n",
       "      <td>4.541376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-06</th>\n",
       "      <td>5.274842</td>\n",
       "      <td>9.623082</td>\n",
       "      <td>2.269901</td>\n",
       "      <td>8.462065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-07</th>\n",
       "      <td>2.916445</td>\n",
       "      <td>9.918241</td>\n",
       "      <td>6.267881</td>\n",
       "      <td>7.222170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-08</th>\n",
       "      <td>0.301662</td>\n",
       "      <td>2.117354</td>\n",
       "      <td>6.077893</td>\n",
       "      <td>4.909039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-09</th>\n",
       "      <td>7.842920</td>\n",
       "      <td>8.775480</td>\n",
       "      <td>6.816798</td>\n",
       "      <td>5.011849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-10</th>\n",
       "      <td>4.276277</td>\n",
       "      <td>7.454491</td>\n",
       "      <td>6.334262</td>\n",
       "      <td>3.276305</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-07-01  0.844460  6.739471  3.788768  8.164879\n",
       "2019-07-02  2.249147  1.227615  7.817358  0.421079\n",
       "2019-07-03  3.858455  6.100323  1.066838  6.624229\n",
       "2019-07-04  9.567775  7.707239  8.438617  6.708416\n",
       "2019-07-05  6.514836  8.544937  9.145777  4.541376\n",
       "2019-07-06  5.274842  9.623082  2.269901  8.462065\n",
       "2019-07-07  2.916445  9.918241  6.267881  7.222170\n",
       "2019-07-08  0.301662  2.117354  6.077893  4.909039\n",
       "2019-07-09  7.842920  8.775480  6.816798  5.011849\n",
       "2019-07-10  4.276277  7.454491  6.334262  3.276305"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates3_2 = pd.date_range('20190701', periods=10)\n",
    "zreo_one_distribute = np.random.rand(10,4)*10 # 10行4列\n",
    "list = ['open','high','low','close']\n",
    "df3_2 = pd.DataFrame(zreo_one_distribute, index=dates3_2, columns=list)\n",
    "df3_2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### concat（纵向拼接+横向拼接）\n",
    "\n",
    "#### axis=0表示纵向拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>4.575004</td>\n",
       "      <td>9.456158</td>\n",
       "      <td>7.072233</td>\n",
       "      <td>7.339954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.448908</td>\n",
       "      <td>0.949864</td>\n",
       "      <td>5.550604</td>\n",
       "      <td>6.062410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>8.779756</td>\n",
       "      <td>4.377672</td>\n",
       "      <td>5.888814</td>\n",
       "      <td>1.621226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.814200</td>\n",
       "      <td>6.065218</td>\n",
       "      <td>3.297106</td>\n",
       "      <td>3.688930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.817728</td>\n",
       "      <td>6.706026</td>\n",
       "      <td>5.447670</td>\n",
       "      <td>5.185773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.124675</td>\n",
       "      <td>0.461762</td>\n",
       "      <td>3.937787</td>\n",
       "      <td>3.695477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.157564</td>\n",
       "      <td>0.449706</td>\n",
       "      <td>3.000842</td>\n",
       "      <td>4.793000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>3.951076</td>\n",
       "      <td>7.059597</td>\n",
       "      <td>8.345769</td>\n",
       "      <td>0.938861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>8.107833</td>\n",
       "      <td>6.684679</td>\n",
       "      <td>6.655880</td>\n",
       "      <td>7.739734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-01</th>\n",
       "      <td>0.844460</td>\n",
       "      <td>6.739471</td>\n",
       "      <td>3.788768</td>\n",
       "      <td>8.164879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-02</th>\n",
       "      <td>2.249147</td>\n",
       "      <td>1.227615</td>\n",
       "      <td>7.817358</td>\n",
       "      <td>0.421079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-03</th>\n",
       "      <td>3.858455</td>\n",
       "      <td>6.100323</td>\n",
       "      <td>1.066838</td>\n",
       "      <td>6.624229</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-04</th>\n",
       "      <td>9.567775</td>\n",
       "      <td>7.707239</td>\n",
       "      <td>8.438617</td>\n",
       "      <td>6.708416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-05</th>\n",
       "      <td>6.514836</td>\n",
       "      <td>8.544937</td>\n",
       "      <td>9.145777</td>\n",
       "      <td>4.541376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-06</th>\n",
       "      <td>5.274842</td>\n",
       "      <td>9.623082</td>\n",
       "      <td>2.269901</td>\n",
       "      <td>8.462065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-07</th>\n",
       "      <td>2.916445</td>\n",
       "      <td>9.918241</td>\n",
       "      <td>6.267881</td>\n",
       "      <td>7.222170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-08</th>\n",
       "      <td>0.301662</td>\n",
       "      <td>2.117354</td>\n",
       "      <td>6.077893</td>\n",
       "      <td>4.909039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-09</th>\n",
       "      <td>7.842920</td>\n",
       "      <td>8.775480</td>\n",
       "      <td>6.816798</td>\n",
       "      <td>5.011849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-10</th>\n",
       "      <td>4.276277</td>\n",
       "      <td>7.454491</td>\n",
       "      <td>6.334262</td>\n",
       "      <td>3.276305</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  5.192434  5.216640  4.693987  4.987835\n",
       "2019-06-02  4.575004  9.456158  7.072233  7.339954\n",
       "2019-06-03  6.448908  0.949864  5.550604  6.062410\n",
       "2019-06-04  8.779756  4.377672  5.888814  1.621226\n",
       "2019-06-05  8.814200  6.065218  3.297106  3.688930\n",
       "2019-06-06  7.817728  6.706026  5.447670  5.185773\n",
       "2019-06-07  9.124675  0.461762  3.937787  3.695477\n",
       "2019-06-08  6.157564  0.449706  3.000842  4.793000\n",
       "2019-06-09  3.951076  7.059597  8.345769  0.938861\n",
       "2019-06-10  8.107833  6.684679  6.655880  7.739734\n",
       "2019-07-01  0.844460  6.739471  3.788768  8.164879\n",
       "2019-07-02  2.249147  1.227615  7.817358  0.421079\n",
       "2019-07-03  3.858455  6.100323  1.066838  6.624229\n",
       "2019-07-04  9.567775  7.707239  8.438617  6.708416\n",
       "2019-07-05  6.514836  8.544937  9.145777  4.541376\n",
       "2019-07-06  5.274842  9.623082  2.269901  8.462065\n",
       "2019-07-07  2.916445  9.918241  6.267881  7.222170\n",
       "2019-07-08  0.301662  2.117354  6.077893  4.909039\n",
       "2019-07-09  7.842920  8.775480  6.816798  5.011849\n",
       "2019-07-10  4.276277  7.454491  6.334262  3.276305"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pd.concat([df3_1,df3_2],axis=0)\n",
    "pd.concat([df3_1,df3_2],axis='index')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### axis=1表示横向拼接，index对不上的会用NaN填充："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>4.575004</td>\n",
       "      <td>9.456158</td>\n",
       "      <td>7.072233</td>\n",
       "      <td>7.339954</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.448908</td>\n",
       "      <td>0.949864</td>\n",
       "      <td>5.550604</td>\n",
       "      <td>6.062410</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>8.779756</td>\n",
       "      <td>4.377672</td>\n",
       "      <td>5.888814</td>\n",
       "      <td>1.621226</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.814200</td>\n",
       "      <td>6.065218</td>\n",
       "      <td>3.297106</td>\n",
       "      <td>3.688930</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.817728</td>\n",
       "      <td>6.706026</td>\n",
       "      <td>5.447670</td>\n",
       "      <td>5.185773</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.124675</td>\n",
       "      <td>0.461762</td>\n",
       "      <td>3.937787</td>\n",
       "      <td>3.695477</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.157564</td>\n",
       "      <td>0.449706</td>\n",
       "      <td>3.000842</td>\n",
       "      <td>4.793000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>3.951076</td>\n",
       "      <td>7.059597</td>\n",
       "      <td>8.345769</td>\n",
       "      <td>0.938861</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>8.107833</td>\n",
       "      <td>6.684679</td>\n",
       "      <td>6.655880</td>\n",
       "      <td>7.739734</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-01</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.844460</td>\n",
       "      <td>6.739471</td>\n",
       "      <td>3.788768</td>\n",
       "      <td>8.164879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-02</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.249147</td>\n",
       "      <td>1.227615</td>\n",
       "      <td>7.817358</td>\n",
       "      <td>0.421079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-03</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.858455</td>\n",
       "      <td>6.100323</td>\n",
       "      <td>1.066838</td>\n",
       "      <td>6.624229</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-04</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9.567775</td>\n",
       "      <td>7.707239</td>\n",
       "      <td>8.438617</td>\n",
       "      <td>6.708416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-05</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.514836</td>\n",
       "      <td>8.544937</td>\n",
       "      <td>9.145777</td>\n",
       "      <td>4.541376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-06</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.274842</td>\n",
       "      <td>9.623082</td>\n",
       "      <td>2.269901</td>\n",
       "      <td>8.462065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-07</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.916445</td>\n",
       "      <td>9.918241</td>\n",
       "      <td>6.267881</td>\n",
       "      <td>7.222170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-08</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.301662</td>\n",
       "      <td>2.117354</td>\n",
       "      <td>6.077893</td>\n",
       "      <td>4.909039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-09</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.842920</td>\n",
       "      <td>8.775480</td>\n",
       "      <td>6.816798</td>\n",
       "      <td>5.011849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.276277</td>\n",
       "      <td>7.454491</td>\n",
       "      <td>6.334262</td>\n",
       "      <td>3.276305</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close      open      high  \\\n",
       "2019-06-01  5.192434  5.216640  4.693987  4.987835       NaN       NaN   \n",
       "2019-06-02  4.575004  9.456158  7.072233  7.339954       NaN       NaN   \n",
       "2019-06-03  6.448908  0.949864  5.550604  6.062410       NaN       NaN   \n",
       "2019-06-04  8.779756  4.377672  5.888814  1.621226       NaN       NaN   \n",
       "2019-06-05  8.814200  6.065218  3.297106  3.688930       NaN       NaN   \n",
       "2019-06-06  7.817728  6.706026  5.447670  5.185773       NaN       NaN   \n",
       "2019-06-07  9.124675  0.461762  3.937787  3.695477       NaN       NaN   \n",
       "2019-06-08  6.157564  0.449706  3.000842  4.793000       NaN       NaN   \n",
       "2019-06-09  3.951076  7.059597  8.345769  0.938861       NaN       NaN   \n",
       "2019-06-10  8.107833  6.684679  6.655880  7.739734       NaN       NaN   \n",
       "2019-07-01       NaN       NaN       NaN       NaN  0.844460  6.739471   \n",
       "2019-07-02       NaN       NaN       NaN       NaN  2.249147  1.227615   \n",
       "2019-07-03       NaN       NaN       NaN       NaN  3.858455  6.100323   \n",
       "2019-07-04       NaN       NaN       NaN       NaN  9.567775  7.707239   \n",
       "2019-07-05       NaN       NaN       NaN       NaN  6.514836  8.544937   \n",
       "2019-07-06       NaN       NaN       NaN       NaN  5.274842  9.623082   \n",
       "2019-07-07       NaN       NaN       NaN       NaN  2.916445  9.918241   \n",
       "2019-07-08       NaN       NaN       NaN       NaN  0.301662  2.117354   \n",
       "2019-07-09       NaN       NaN       NaN       NaN  7.842920  8.775480   \n",
       "2019-07-10       NaN       NaN       NaN       NaN  4.276277  7.454491   \n",
       "\n",
       "                 low     close  \n",
       "2019-06-01       NaN       NaN  \n",
       "2019-06-02       NaN       NaN  \n",
       "2019-06-03       NaN       NaN  \n",
       "2019-06-04       NaN       NaN  \n",
       "2019-06-05       NaN       NaN  \n",
       "2019-06-06       NaN       NaN  \n",
       "2019-06-07       NaN       NaN  \n",
       "2019-06-08       NaN       NaN  \n",
       "2019-06-09       NaN       NaN  \n",
       "2019-06-10       NaN       NaN  \n",
       "2019-07-01  3.788768  8.164879  \n",
       "2019-07-02  7.817358  0.421079  \n",
       "2019-07-03  1.066838  6.624229  \n",
       "2019-07-04  8.438617  6.708416  \n",
       "2019-07-05  9.145777  4.541376  \n",
       "2019-07-06  2.269901  8.462065  \n",
       "2019-07-07  6.267881  7.222170  \n",
       "2019-07-08  6.077893  4.909039  \n",
       "2019-07-09  6.816798  5.011849  \n",
       "2019-07-10  6.334262  3.276305  "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pd.concat([df3_1,df3_2],axis=1)\n",
    "pd.concat([df3_1,df3_2],axis='columns')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 添加数据 append"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>4.575004</td>\n",
       "      <td>9.456158</td>\n",
       "      <td>7.072233</td>\n",
       "      <td>7.339954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.448908</td>\n",
       "      <td>0.949864</td>\n",
       "      <td>5.550604</td>\n",
       "      <td>6.062410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>8.779756</td>\n",
       "      <td>4.377672</td>\n",
       "      <td>5.888814</td>\n",
       "      <td>1.621226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.814200</td>\n",
       "      <td>6.065218</td>\n",
       "      <td>3.297106</td>\n",
       "      <td>3.688930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.817728</td>\n",
       "      <td>6.706026</td>\n",
       "      <td>5.447670</td>\n",
       "      <td>5.185773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.124675</td>\n",
       "      <td>0.461762</td>\n",
       "      <td>3.937787</td>\n",
       "      <td>3.695477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.157564</td>\n",
       "      <td>0.449706</td>\n",
       "      <td>3.000842</td>\n",
       "      <td>4.793000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>3.951076</td>\n",
       "      <td>7.059597</td>\n",
       "      <td>8.345769</td>\n",
       "      <td>0.938861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>8.107833</td>\n",
       "      <td>6.684679</td>\n",
       "      <td>6.655880</td>\n",
       "      <td>7.739734</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  5.192434  5.216640  4.693987  4.987835\n",
       "2019-06-02  4.575004  9.456158  7.072233  7.339954\n",
       "2019-06-03  6.448908  0.949864  5.550604  6.062410\n",
       "2019-06-04  8.779756  4.377672  5.888814  1.621226\n",
       "2019-06-05  8.814200  6.065218  3.297106  3.688930\n",
       "2019-06-06  7.817728  6.706026  5.447670  5.185773\n",
       "2019-06-07  9.124675  0.461762  3.937787  3.695477\n",
       "2019-06-08  6.157564  0.449706  3.000842  4.793000\n",
       "2019-06-09  3.951076  7.059597  8.345769  0.938861\n",
       "2019-06-10  8.107833  6.684679  6.655880  7.739734"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open     5.192434\n",
       "high     5.216640\n",
       "low      4.693987\n",
       "close    4.987835\n",
       "Name: 2019-06-01 00:00:00, dtype: float64"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取行索引为1的整行数据\n",
    "s3 = df3_1.iloc[0]\n",
    "s3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>4.575004</td>\n",
       "      <td>9.456158</td>\n",
       "      <td>7.072233</td>\n",
       "      <td>7.339954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.448908</td>\n",
       "      <td>0.949864</td>\n",
       "      <td>5.550604</td>\n",
       "      <td>6.062410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>8.779756</td>\n",
       "      <td>4.377672</td>\n",
       "      <td>5.888814</td>\n",
       "      <td>1.621226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.814200</td>\n",
       "      <td>6.065218</td>\n",
       "      <td>3.297106</td>\n",
       "      <td>3.688930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.817728</td>\n",
       "      <td>6.706026</td>\n",
       "      <td>5.447670</td>\n",
       "      <td>5.185773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.124675</td>\n",
       "      <td>0.461762</td>\n",
       "      <td>3.937787</td>\n",
       "      <td>3.695477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.157564</td>\n",
       "      <td>0.449706</td>\n",
       "      <td>3.000842</td>\n",
       "      <td>4.793000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>3.951076</td>\n",
       "      <td>7.059597</td>\n",
       "      <td>8.345769</td>\n",
       "      <td>0.938861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>8.107833</td>\n",
       "      <td>6.684679</td>\n",
       "      <td>6.655880</td>\n",
       "      <td>7.739734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  5.192434  5.216640  4.693987  4.987835\n",
       "2019-06-02  4.575004  9.456158  7.072233  7.339954\n",
       "2019-06-03  6.448908  0.949864  5.550604  6.062410\n",
       "2019-06-04  8.779756  4.377672  5.888814  1.621226\n",
       "2019-06-05  8.814200  6.065218  3.297106  3.688930\n",
       "2019-06-06  7.817728  6.706026  5.447670  5.185773\n",
       "2019-06-07  9.124675  0.461762  3.937787  3.695477\n",
       "2019-06-08  6.157564  0.449706  3.000842  4.793000\n",
       "2019-06-09  3.951076  7.059597  8.345769  0.938861\n",
       "2019-06-10  8.107833  6.684679  6.655880  7.739734\n",
       "2019-06-01  5.192434  5.216640  4.693987  4.987835"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ignore_index=False 表示索引不变\n",
    "df3_1.append(s3, ignore_index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4.575004</td>\n",
       "      <td>9.456158</td>\n",
       "      <td>7.072233</td>\n",
       "      <td>7.339954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6.448908</td>\n",
       "      <td>0.949864</td>\n",
       "      <td>5.550604</td>\n",
       "      <td>6.062410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8.779756</td>\n",
       "      <td>4.377672</td>\n",
       "      <td>5.888814</td>\n",
       "      <td>1.621226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8.814200</td>\n",
       "      <td>6.065218</td>\n",
       "      <td>3.297106</td>\n",
       "      <td>3.688930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7.817728</td>\n",
       "      <td>6.706026</td>\n",
       "      <td>5.447670</td>\n",
       "      <td>5.185773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9.124675</td>\n",
       "      <td>0.461762</td>\n",
       "      <td>3.937787</td>\n",
       "      <td>3.695477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>6.157564</td>\n",
       "      <td>0.449706</td>\n",
       "      <td>3.000842</td>\n",
       "      <td>4.793000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>3.951076</td>\n",
       "      <td>7.059597</td>\n",
       "      <td>8.345769</td>\n",
       "      <td>0.938861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>8.107833</td>\n",
       "      <td>6.684679</td>\n",
       "      <td>6.655880</td>\n",
       "      <td>7.739734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        open      high       low     close\n",
       "0   5.192434  5.216640  4.693987  4.987835\n",
       "1   4.575004  9.456158  7.072233  7.339954\n",
       "2   6.448908  0.949864  5.550604  6.062410\n",
       "3   8.779756  4.377672  5.888814  1.621226\n",
       "4   8.814200  6.065218  3.297106  3.688930\n",
       "5   7.817728  6.706026  5.447670  5.185773\n",
       "6   9.124675  0.461762  3.937787  3.695477\n",
       "7   6.157564  0.449706  3.000842  4.793000\n",
       "8   3.951076  7.059597  8.345769  0.938861\n",
       "9   8.107833  6.684679  6.655880  7.739734\n",
       "10  5.192434  5.216640  4.693987  4.987835"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ignore_index=True表示重置\n",
    "df3_1.append(s3,ignore_index=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 移除重复数据 duplicated"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>4.575004</td>\n",
       "      <td>9.456158</td>\n",
       "      <td>7.072233</td>\n",
       "      <td>7.339954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.448908</td>\n",
       "      <td>0.949864</td>\n",
       "      <td>5.550604</td>\n",
       "      <td>6.062410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>8.779756</td>\n",
       "      <td>4.377672</td>\n",
       "      <td>5.888814</td>\n",
       "      <td>1.621226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.814200</td>\n",
       "      <td>6.065218</td>\n",
       "      <td>3.297106</td>\n",
       "      <td>3.688930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.817728</td>\n",
       "      <td>6.706026</td>\n",
       "      <td>5.447670</td>\n",
       "      <td>5.185773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.124675</td>\n",
       "      <td>0.461762</td>\n",
       "      <td>3.937787</td>\n",
       "      <td>3.695477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>6.157564</td>\n",
       "      <td>0.449706</td>\n",
       "      <td>3.000842</td>\n",
       "      <td>4.793000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>3.951076</td>\n",
       "      <td>7.059597</td>\n",
       "      <td>8.345769</td>\n",
       "      <td>0.938861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>8.107833</td>\n",
       "      <td>6.684679</td>\n",
       "      <td>6.655880</td>\n",
       "      <td>7.739734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>5.192434</td>\n",
       "      <td>5.216640</td>\n",
       "      <td>4.693987</td>\n",
       "      <td>4.987835</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  5.192434  5.216640  4.693987  4.987835\n",
       "2019-06-02  4.575004  9.456158  7.072233  7.339954\n",
       "2019-06-03  6.448908  0.949864  5.550604  6.062410\n",
       "2019-06-04  8.779756  4.377672  5.888814  1.621226\n",
       "2019-06-05  8.814200  6.065218  3.297106  3.688930\n",
       "2019-06-06  7.817728  6.706026  5.447670  5.185773\n",
       "2019-06-07  9.124675  0.461762  3.937787  3.695477\n",
       "2019-06-08  6.157564  0.449706  3.000842  4.793000\n",
       "2019-06-09  3.951076  7.059597  8.345769  0.938861\n",
       "2019-06-10  8.107833  6.684679  6.655880  7.739734\n",
       "2019-06-01  5.192434  5.216640  4.693987  4.987835"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z3 = df3_1.append(s3, ignore_index=False)\n",
    "z3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    False\n",
       "2019-06-02    False\n",
       "2019-06-03    False\n",
       "2019-06-04    False\n",
       "2019-06-05    False\n",
       "2019-06-06    False\n",
       "2019-06-07    False\n",
       "2019-06-08    False\n",
       "2019-06-09    False\n",
       "2019-06-10    False\n",
       "2019-06-01     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回bool值。True代表是重复数据；False代表非重复数据。\n",
    "z3.duplicated()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
